package edu.mercer.sse661.ao;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.Callable;

import com.google.common.base.Throwables;

/**
 * Download URL contents to StringBuilder; run as Callable.<p>
 *
 * Callable task for Active Object Pattern demonstration.<p>
 * 
 * @see Callable
 */

public class DownloadURL implements Callable<StringBuilder>
{
	private String _url; 

	DownloadURL( final String url )
	{
		try
		{
			new URL( url );
			
			_url = url;
		
		} 
		catch( final MalformedURLException err )
		{
			throw new RuntimeException( "URL invalid: " 
					+ url 
					+ " " 
					+ Throwables.getStackTraceAsString(err) );
			
		}//try
		
	}//constructor
	
	
	public StringBuilder call()	
	{
		return new DownloadURLFunction().apply( _url );		
		
	}//method
	

}//class
